/*
* Copyright 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
*/
package com.laihuichuxing.producerAndConsumer;

import com.laihuichuxing.concurrent.BasicThreadPool;
import com.laihuichuxing.concurrent.ThreadPool;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;

/**
 * Description:
 *
 * @author: Qinxuefeng
 * @since: 1.0
 * Create Date Time: 2018/12/12 15:05
 * Update Date Time:
 */

public class Main {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<Product> productBlockingQueue = new LinkedBlockingDeque<>();
        ThreadPool threadPool = new BasicThreadPool(8, 16, 16, 100);
        for(int i=0;i<5;i++){
            threadPool.execute(new Producer(productBlockingQueue,i));
            threadPool.execute(new Consumer(productBlockingQueue,i));
        }
        TimeUnit.SECONDS.sleep(100);
        threadPool.shutdown();
        /*ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 5; i++) {
            executorService.execute(new Producer(productBlockingQueue, i));
            executorService.execute(new Consumer(productBlockingQueue, i));
        }

        TimeUnit.SECONDS.sleep(10);
        executorService.shutdownNow();*/

    }
}
